package zsj.androidknife.utilsImpl;

import java.util.Objects;
import java.util.concurrent.ExecutorService;

import zsj.androidknife.R;
import zsj.androidknife.ThreadPool.TaskExecutor;
import zsj.androidknife.utils.BackgroundAction;
import zsj.androidknife.utils.IThreadUtils;
import zsj.androidknife.utils.SimpleBackgroundAction;
import zsj.androidknife.utils.SimpleUiAction;
import zsj.androidknife.utils.UiAction;

/**
 * Created by Administrator on 2016/4/19 0019.
 */
public class ThreadUtils implements IThreadUtils{
    private TaskExecutor executor;

    @Override
    public void startSimpleBackgroundTask(SimpleBackgroundAction backgroundAction, SimpleUiAction uiAction)
    {
        executor.submitBackgroundForResult(backgroundAction,uiAction);
    }
    @Override
    public <P,R> void startBackgroundTask(BackgroundAction<P,R> backgroundAction,UiAction<R> uiAction,P param)
    {
        executor.submitBackgroundForResult(backgroundAction,uiAction,param);
    }

    @Override
    public void startSimpleBackgroundTask(SimpleBackgroundAction backgroundAction) {
        startSimpleBackgroundTask(backgroundAction,null);
    }

    private static class InstanceHolder
    {
        public static ThreadUtils INSTANCE = new ThreadUtils();
    }
    public static  ThreadUtils getInstance()
    {
        return InstanceHolder.INSTANCE;
    }
    private ThreadUtils(){
        executor = TaskExecutor.getInstance();
    }
}
